package com.hex.ds.hdtp.core.web.license.activation.controller;

import com.hex.ds.hdtp.core.app.license.activation.service.IFuncActivationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;

@Slf4j
@RestController
@Api(tags = "方法激活")
@RequestMapping("/api/license/activation")
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class FuncActivationController {

    private final IFuncActivationService funcActivationService;


    @PostMapping(value = "/uploadLicense")
    @ApiOperation("上传转换脚本")
    public ResponseEntity uploadLicense(HttpServletRequest httpServletRequest) throws Exception {
        log.info("进入【FuncActivationController.uploadLicense】方法");
        List<MultipartFile> multipartFileList = ((MultipartHttpServletRequest) httpServletRequest).getFiles("fileList");
        funcActivationService.uploadLicense(multipartFileList);
        return ResponseEntity.ok("激活成功");
    }
}
